﻿Imports Infragistics.Win.UltraWinGrid

Public Class dmvattu1
    'state : 0 mặc định - trạng thái 1- tạo mới 2 sửa 3 - xóa
    Private state As Integer
    'load form
    Dim isLoad As Boolean = True
    Private Sub loadDuLieu()
        If isLoad Then
            Me.Cursor = Cursors.WaitCursor
            Me.DmvattuTableAdapter.Fill(Me.ErpharmaDataSet.dmvattu)
            Me.Dmvattu_donvitinhTableAdapter.Fill(Me.ErpharmaDataSet.dmvattu_donvitinh)
            Me.Dmvattu_hoatchatTableAdapter.Fill(Me.ErpharmaDataSet.dmvattu_hoatchat)

            'set giao diện
            Me.dmvattuIUltraGrid_ThongTin.setGiaoDien_Doi_ThongTin()
            Me.dmvattuIUltraGrid_DanhSach.setGiaoDienTuyBien()

            'set tìm kiếm

            'danh sách
            Me.dmvattuIUltraGrid_DanhSach.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmvattu, Me.DmvattuBindingSource, Me.DmvattuTableAdapter, Me.ErpharmaDataSet)
            Me.dmvattuIUltraGrid_DanhSach.setTimKiemTrenCotUltraGrid()

            'thông tin
            Me.dmvattuIUltraGrid_ThongTin.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmvattu, Me.DmvattuBindingSource, Me.DmvattuTableAdapter, Me.ErpharmaDataSet)

            Me.DmkhachhangTableAdapter.Fill(Me.ErpharmaDataSet.dmkhachhang)
            Me.dmvattuIUltraGrid_ThongTin.setThemIUltraDropDown(Me.dmkhachhangIUltraDropDown, Me.ErpharmaDataSet.dmkhachhang)
            Me.dmvattuIUltraGrid_ThongTin.setTimKiemTheoShift()
            Me.dmkhachhangIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.dmkhachhangIUltraDropDown.setGiaoDien()

            Me.DmtinhtrangTableAdapter.Fill(Me.ErpharmaDataSet.dmtinhtrang)
            Me.dmvattuIUltraGrid_ThongTin.setThemIUltraDropDown(Me.DmtinhtrangIUltraDropDown, Me.ErpharmaDataSet.dmtinhtrang)
            Me.DmtinhtrangIUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.DmtinhtrangIUltraDropDown.setGiaoDien()

            Me.DmkhoTableAdapter.Fill(Me.ErpharmaDataSet.dmkho)
            Me.dmvattuIUltraGrid_ThongTin.setThemIUltraDropDown(Me.dmkho_IUltraDropDown, Me.ErpharmaDataSet.dmkho)
            Me.dmkho_IUltraDropDown.setGiaoDien_An_ColumnHeader()
            Me.dmkho_IUltraDropDown.setGiaoDien()

            'gán mặc định
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("tyle", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("dientich", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("chieucao", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("thoigiannhaphang", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("thoigiankhiemnghiem", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("thoigianxuly", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("tilequidoi", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("khoiluongtinh", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("trongluonggop", 0)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("dungbom", False)
            Me.dmvattuIUltraGrid_ThongTin.setMacDinh("handung", Today)

            'bắt lỗi

            Me.dmvattuIUltraGrid_ThongTin.setCotBatLoi("ma")
            Me.dmvattuIUltraGrid_ThongTin.setCotBatLoi("ten1")

            'thông tin don vi tinh
            Me.dmvattu_donvitinhIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmvattu_donvitinh, Me.Dmvattu_donvitinhBindingSource, Me.Dmvattu_donvitinhTableAdapter, Me.ErpharmaDataSet)
            Me.dmvattu_donvitinhIUltraGrid.setChoPhepMenuStrip()

            'thông tin hoat chat
            Me.dmvattu_hoatchatIUltraGrid.setDoiTuongXuLyDuLieu(Me.ErpharmaDataSet.dmvattu_hoatchat, Me.Dmvattu_hoatchatBindingSource, Me.Dmvattu_hoatchatTableAdapter, Me.ErpharmaDataSet)
            Me.dmvattu_hoatchatIUltraGrid.setChoPhepMenuStrip()
            'tìm kiếm
            Me.dmvattu_donvitinhIUltraGrid.setGiaoDienTuyBien()
            Me.dmvattu_hoatchatIUltraGrid.setGiaoDienTuyBien()
            Me.dmvattu_donvitinhIUltraGrid.setTimKiemTrenCotUltraGrid()
            Me.dmvattu_hoatchatIUltraGrid.setTimKiemTrenCotUltraGrid()
            'Me.Ketoantienmat_thongtinchinhIUltraGrid_TimKiem.setGroupBy("ma")
            'Me.Ketoantienmat_thongtinthueIUltraGrid_TimKiem.setGroupBy("ma")
            Me.dmvattuIUltraGrid_ThongTin.setReadonly(True)
            Me.dmvattu_donvitinhIUltraGrid.setReadonly(True)
            Me.dmvattu_hoatchatIUltraGrid.setReadonly(True)
            Me.Cursor = Cursors.Default
            Me.isLoad = False
        End If
    End Sub
    Private Sub dmvattu1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.loadDuLieu()
    End Sub
    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = (Keys.Control Or Keys.N) Then
            Return getTaoMoi()
        End If
        If keyData = (Keys.Control Or Keys.S) Then
            Return getLuu()
        End If
        If keyData = (Keys.Control Or Keys.E) Then
            Return getSua()
        End If
        If keyData = (Keys.Control Or Keys.D) Then
            Return Me.dmvattuIUltraGrid_ThongTin.getXoa()
        End If
        If keyData = (Keys.Control Or Keys.P) Then
            'Return Me.getIn()
        End If
        If keyData = (Keys.Control Or Keys.R) Then
            Return Me.dmvattuIUltraGrid_ThongTin.getRefresh()
        End If
        If (keyData = (Keys.Control Or Keys.Q)) Then
            Return getThoat()
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
    Private Sub setReadOnly(ByVal isTrue As Boolean)
        Me.dmvattuIUltraGrid_ThongTin.setReadonly(isTrue)
        Me.dmvattuIUltraGrid_DanhSach.setReadonly(isTrue)
        Me.dmvattu_hoatchatIUltraGrid.setReadonly(isTrue)
        Me.dmvattu_donvitinhIUltraGrid.setReadonly(isTrue)
    End Sub
    Private Function getTaoMoi()
        If (Me.dmvattuIUltraGrid_ThongTin.getTaoMoi()) Then
            Me.setReadOnly(False)
            Me.state = 1
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnTaoMoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTaoMoi.Click
        getTaoMoi()
    End Sub
    Private Function getLuu()
      
        If Me.dmvattuIUltraGrid_ThongTin.getLuu() Or Me.dmvattu_donvitinhIUltraGrid.getLuuNgam() Or Me.dmvattu_hoatchatIUltraGrid.getLuuNgam() Then
            Me.setReadOnly(True)
            Me.state = 0
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLuu.Click
        getLuu()
    End Sub
    Private Function getSua()
        If dmvattuIUltraGrid_ThongTin.getSua() And Me.dmvattu_donvitinhIUltraGrid.getSua And Me.dmvattu_hoatchatIUltraGrid.getSua Then
            Me.setReadOnly(False)
            Me.state = 2
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        getSua()
    End Sub
    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        dmvattuIUltraGrid_ThongTin.getXoa()
    End Sub

    Private Sub btnLamTuoi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLamTuoi.Click
        Me.dmvattuIUltraGrid_ThongTin.getRefresh()
    End Sub

    Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click
      
    End Sub
    Private Function getThoat()
        If Me.dmvattuIUltraGrid_ThongTin.getCoThayDoiDuLieuKhong Or Me.dmvattu_donvitinhIUltraGrid.getCoThayDoiDuLieuKhong Or Me.dmvattu_hoatchatIUltraGrid.getCoThayDoiDuLieuKhong Then
            If dmvattuIUltraGrid_ThongTin.getLuu Then
                dmvattu_donvitinhIUltraGrid.getLuuNgam()
                dmvattu_hoatchatIUltraGrid.getLuuNgam()
            End If
            Return True
        Else
            Me.Dispose()
            Me.Close()
            Return True
        End If
    End Function
    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        getThoat()
    End Sub
   

End Class